{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d28c895c",
   "metadata": {},
   "source": [
    "* 日期：2022-09-21 \\ week05\n",
    "* 课程：python\n",
    "* 记录人：liuxu"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e19dfd7f",
   "metadata": {},
   "source": [
    "# 本周学习内容  \n",
    "> 1. 数值（number）\n",
    "\n",
    ">> 1. 定义 2.方法\n",
    "\n",
    "> 2. 字符串（string）\n",
    "\n",
    ">> 1. 定义 2.方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f03c27d",
   "metadata": {},
   "source": [
    "## 1.数值  \n",
    "> 1. 对数值进行分类\n",
    "\n",
    ">> 1.整数（int） 2.浮点型（float） 3.复数（complex）\n",
    "\n",
    "> 2.数值的运算法则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "232ee512",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 整型\n",
    "a = 99\n",
    "print(a, type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "418a1688",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# 浮点型\n",
    "b = 99.9\n",
    "print(b, type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "55524a0c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "198.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "c = a + b\n",
    "print(c, type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ad9220fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "# 复数（虚数）\n",
    "d = 2 + 3j\n",
    "print(d, type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cef93f2a",
   "metadata": {},
   "source": [
    "## 2.字符串  \n",
    "> 1. 定义\n",
    "> 2. 方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9507a45c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = 'Alex'\n",
    "print(name, type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "811296bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = '18'\n",
    "# noinspection ProblematicWhitespace\n",
    "b = '22'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "21b00246",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18 18\n",
      "<class 'str'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a = '18'\n",
    "b = '18'\n",
    "print(a, b)\n",
    "print(type(a), type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "29a9b6b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案1\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "15e9d273",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"do't\""
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案2  \\ 后面的内容是“符号”，转义，\\自动消失\n",
    "'do\\'t'\n",
    "#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1bc16e8a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# *正则表达式，有兴趣的同学可以自学"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e5f9ae0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三个引号，可以包含任何文本\n",
    "# 作用：\n",
    "# 1. 保持原数据的结构，包含符号，换行等。\n",
    "# 2. 可以用来做代码注释。\n",
    "NFU_招投标_HTML = \"\"\"\n",
    "<ul class=\"tzg-div\" style=\"display: block;\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzg-nr\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzg-time\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzg-p\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告...\n",
    "    </a>\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "825d80f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "<ul class=\"tzg-div\" style=\"display: block;\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzg-nr\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzg-time\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzg-p\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告...\n",
      "    </a>\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(NFU_招投标_HTML)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ccec562d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "### 三个引号来代码注释\n",
    "\n",
    "南方学院学校要闻 = \"https://www.nfu.edu.cn/xxyw/index\"\n",
    "页面后缀 = \".htm\"\n",
    "page = 5\n",
    "\n",
    "\"\"\"\n",
    "for i in range(page):\n",
    "    print(南方学院学校要闻 + str(i) + 页面后缀)  # 字符串拼接\n",
    "    random_num = random.randint(1,10)\n",
    "    print(\"该次停留\",random_num,'秒')\n",
    "    time.sleep(random_num)\n",
    "\"\"\"\n",
    "\n",
    "print(\"hello world!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1bf51602",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院坐落于广州市从化温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "92889d62",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0]  # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "443d79c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[1]  # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "274a22ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title)  # 检查文本的总长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "da985004",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d92d9f40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6]  # 取一定范围的值，这种方法我们称其为“切片”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "64c40df6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "a775d15f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 温\n",
      "15 泉\n",
      "16 镇\n"
     ]
    }
   ],
   "source": [
    "## enumerate 枚举，既可以获取到内容 item ，又可以获取到  索引值 index。\n",
    "## 利用for循环 遍历文本信息\n",
    "for i, j in enumerate(title):\n",
    "    print(i, j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "1beb7da8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "广州这个词在这段文本中\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "广州这个词在这段文本中\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 温\n",
      "15 泉\n",
      "16 镇\n"
     ]
    }
   ],
   "source": [
    "# 思考，如何判断一段文本中是否存在“广州”，例如文本  title  中的内容,还可以确定其出现的次数\n",
    "for i, j in enumerate(title):\n",
    "    print(i, j)\n",
    "    if j == \"广\":\n",
    "        if title[i + 1] == \"州\":\n",
    "            print(\"广州这个词在这段文本中\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6781b96",
   "metadata": {},
   "source": [
    "* 2.3 Page59 in 检查成员对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "28776369",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## Page59   in 检查成员对象\n",
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a7d514a",
   "metadata": {},
   "source": [
    "* 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "877eab63",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好，Alex\n"
     ]
    }
   ],
   "source": [
    "print(\"你好\" + \"，\" + \"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "1b1b02dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串不可以和 数字进行连接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "e0746fc3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1, type(1))\n",
    "print(\"1\", type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "aa3a8281",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串不可以 用来运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "5f617fe8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 由于没有分清楚 字符串和数值的概念导致的“笑话”\n",
    "width = \"16\"\n",
    "height = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "3fffe37b",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width * height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "3c7e1118",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'161616161616161616'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9568eba",
   "metadata": {},
   "source": [
    "* 字符串的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "7ae59c79",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "d749c7e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "eb43798d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "5c3f254d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院坐落于广州市从化温泉镇'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "326a5c7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "ed244fbd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院', '广州市从化温泉镇']"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"坐落于\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "66bed273",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = 1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c46d5a31",
   "metadata": {},
   "source": [
    "# 课后：第二章列表预习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "90214233",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "five is greater than two!\n"
     ]
    }
   ],
   "source": [
    "if 5 > 2:\n",
    "    print(\"five is greater than two!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "5329f007",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "hello,world!\n"
     ]
    }
   ],
   "source": [
    "x = 5\n",
    "y = \"hello,world!\"\n",
    "\n",
    "print(x)\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "6bd73eb2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Five is greater than two!\n",
      "Five is greater than two!\n"
     ]
    }
   ],
   "source": [
    "if 5 > 2:\n",
    "    print(\"Five is greater than two!\")\n",
    "    print(\"Five is greater than two!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "3df47713",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cheers, Mate!\n"
     ]
    }
   ],
   "source": [
    "#print(\"Hello, World!\")\n",
    "print(\"Cheers, Mate!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "d1c32b2b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, World!\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "This is a comment\n",
    "written in\n",
    "more than just one line\n",
    "\"\"\"\n",
    "print(\"Hello, World!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "d2ce10bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Orange\n",
      "Banana\n",
      "Cherry\n"
     ]
    }
   ],
   "source": [
    "x, y, z = \"Orange\", \"Banana\", \"Cherry\"\n",
    "print(x)\n",
    "print(y)\n",
    "print(z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "3ef5ae66",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python is fantastic\n",
      "Python is awesome\n"
     ]
    }
   ],
   "source": [
    "x = \"awesome\"\n",
    "\n",
    "\n",
    "def myfunc():\n",
    "    x = \"fantastic\"\n",
    "    print(\"Python is \" + x)\n",
    "\n",
    "\n",
    "myfunc()\n",
    "\n",
    "print(\"Python is \" + x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "adf22b7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13\n"
     ]
    }
   ],
   "source": [
    "a = \"Hello, World!\"\n",
    "print(len(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56214c78",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
